package com.hualan.controller;

import com.hualan.domain.Free;
import com.hualan.service.FreeService;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/free")
public class FreeController {

//    @Autowired
//    private AllFreeService allFreeService;
//    @Autowired
//    private AddFreeService freeService;
//    @Autowired
//    private DelFreeService delFreeService;
//    @Autowired
//    private UpdateService updateService;
    @Autowired
    private FreeService freeService;
    @GetMapping("/getAllList")
    public R getFreeList() {
        return freeService .queryFreeList();
    }
   // 查询
    @GetMapping("/select")
    public R selAllFree(){
        return R.success(freeService.selAllFree());
    }

    @GetMapping("/select1")
    public R selAllFreePage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,@RequestParam(name = "pageSize",defaultValue = "5")int pageSize){
        return R.success(freeService.selAllFreePage(pageNum,pageSize));
    }

    //添加
    @PostMapping("/add")
    public R addFree(Free free){
        return R.success(freeService.addFree(free));


    }

    //按id删除
    @DeleteMapping("/del")
    public R selById(Long id){
        return R.success(
                freeService.delById(id));
    }

    //编辑
    @PostMapping("/update")
    public  R updateFree(Free free){
        return R.success(
                freeService.updateFree(free));
    }

    //模糊查询
    @GetMapping("/like")
    public R selLikeFree(String name){
        List<Free> freeList=
        freeService.selLiskFree(name);
        return R.success(freeList);
    }
}
